package cn.com.dashihui.pay.wx.request;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import com.jfinal.kit.PropKit;

import cn.com.dashihui.kit.CommonKit;
import cn.com.dashihui.pay.wx.kit.Signature;
/**
 * 退款请求封装对象
 * @author Administrator
 *
 */
public class RefOrderReqData {
	
	//每个字段具体的意思请查看API文档
	private String appid; 		//公众号
	private String mch_id; 		//商户id
	private String nonce_str; 	//随机数字
	private String out_trade_no;	//订单号
	private String out_refund_no;	//退款单号   唯一
	private String total_fee;		//订单金额
	private String refund_fee;		//退款金额
	private String refund_desc;		//退款原因
	private String notify_url;		//退款回调
	private String sign; 			//签名
	
    public RefOrderReqData( String out_trade_no,String out_refund_no, String total_fee,String refund_fee,String refund_desc){

        //--------------------------------------------------------------------
        //设置必须数据
        //--------------------------------------------------------------------

        //微信分配的公众号ID（开通公众号之后可以获取到）
        setAppid(PropKit.get("weixinpay.appid"));

        //微信支付分配的商户号ID（开通公众号的微信支付功能之后可以获取到）
        setMch_id(PropKit.get("weixinpay.mch_id"));

        //随机字符串，不长于32 位
        setNonce_str(CommonKit.getRandomStringByLength(32));
        
        
        //商户系统自己生成的唯一的订单号
        setOut_trade_no(out_trade_no);
        
        //退款单号   唯一
        setOut_refund_no(out_refund_no);	
        
    	//订单总金额，单位为分，详见支付金额
        setTotal_fee(total_fee);
        
        //退款总金额，单位为分，详见支付金额
        setRefund_fee(refund_fee);
        
        //退款原因
        setRefund_desc(refund_desc);	
        
        //接收微信支付异步通知回调地址
        setNotify_url(PropKit.get("weixinpay.refundOrderNotifyUrl"));
        
        //根据API给的签名规则进行签名
        String sign = Signature.getSign(toMap());
        setSign(sign);//把签名数据设置到Sign这个属性中
    }
    
	
    
	public String getAppid() {
		return appid;
	}



	public void setAppid(String appid) {
		this.appid = appid;
	}



	public String getMch_id() {
		return mch_id;
	}



	public void setMch_id(String mch_id) {
		this.mch_id = mch_id;
	}



	public String getNonce_str() {
		return nonce_str;
	}



	public void setNonce_str(String nonce_str) {
		this.nonce_str = nonce_str;
	}



	public String getOut_trade_no() {
		return out_trade_no;
	}



	public void setOut_trade_no(String out_trade_no) {
		this.out_trade_no = out_trade_no;
	}



	public String getOut_refund_no() {
		return out_refund_no;
	}



	public void setOut_refund_no(String out_refund_no) {
		this.out_refund_no = out_refund_no;
	}



	public String getTotal_fee() {
		return total_fee;
	}



	public void setTotal_fee(String total_fee) {
		this.total_fee = total_fee;
	}



	public String getRefund_fee() {
		return refund_fee;
	}



	public void setRefund_fee(String refund_fee) {
		this.refund_fee = refund_fee;
	}



	public String getRefund_desc() {
		return refund_desc;
	}



	public void setRefund_desc(String refund_desc) {
		this.refund_desc = refund_desc;
	}



	public String getNotify_url() {
		return notify_url;
	}



	public void setNotify_url(String notify_url) {
		this.notify_url = notify_url;
	}



	public String getSign() {
		return sign;
	}
	public void setSign(String sign) {
		this.sign = sign;
	}
	public Map<String,Object> toMap(){
        Map<String,Object> map = new HashMap<String, Object>();
        Field[] fields = this.getClass().getDeclaredFields();
        for (Field field : fields) {
            Object obj;
            try {
                obj = field.get(this);
                if(obj!=null){
                    map.put(field.getName(), obj);
                }
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return map;
    }
}
